home *** CD-ROM | disk | FTP | other *** search
- LISTING 22 - Adds the assignment operator and copy constructor to
- the Person class
- //person3.cpp
- #include <iostream.h>
- #include <string.h>
- #include <new.h> // for placement new
- #include "person3.h"
-
- Person::Person(const Person & p)
- : birth(p.birth)
- {
- last = clone(p.last);
- first = clone(p.first);
- ssn = clone(p.ssn);
- }
-
- Person & Person::operator=(const Person & p)
- {
- if (this != &p)
- {
- this->Person::~Person();
- new (this) Person(p);
- }
- return *this;
- }
-
- // (other functions as in Listing 20)
-
-